from django.shortcuts import render

from BookApp.models import BookInfo, HeroInfo

# Create your views here.


from django.http import HttpResponse


def findBookName(request):
    """"简易的测试"""
    print("sssssss")
    return HttpResponse('哈哈哈哈哈哈哈,我不干活儿,你别瞎忙!')


def findBookName2(req):
    """简易的测试2,并返回一个测试模板"""

    b = BookInfo.objects.get(id=1)
    return HttpResponse(render(req, "bookappTemplates/test.html", {"name": b.title}))


def showBooks(request):
    """显示网站里所有的图书"""

    # 从数据库获取图书数据
    b = BookInfo.objects.all()
    # 返回渲染的书序
    return HttpResponse(render(request, 'bookappTemplates/books.html', {"book": b}))


def showHeros(request, bid):
    """显示书中的人物"""

    b = BookInfo.objects.get(id=bid)
    h = b.heroinfo_set.all()

    return HttpResponse(render(request, 'bookappTemplates/heros.html', {"hero": h}))
